// const { template } = require("lodash");

const $commentList = $(".comment-list");
const $btn = $("#btn");
axios('http://localhost:3000/db')
.then(function (res) {
    const str = template("tem",res.data);
    $(str).appendTo($commentList)
})

$btn.click(function () {
    const userName = $(":text").val(), content = $("textarea").val();
    if (userName && content) {
        axios.post('http://localhost:3000/comments',{
            "username": userName,
            "content": content
        }).then(function (res) {
            const myData = {"comments": [res.data]}
            const str = template("tem", myData)
            console.log(myData)
            $(str).appendTo($commentList)
        })
    } else {
        alert("用户名或内容不能为空")
    }
})